<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function function</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Contract 1.0.0">
<link rel="up" href="../../reference.html#header.boost.contract.function_hpp" title="Header &lt;boost/contract/function.hpp&gt;">
<link rel="prev" href="destructor.html" title="Function template destructor">
<link rel="next" href="is_old_value_copyable.html" title="Struct template is_old_value_copyable">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="destructor.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.function_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="is_old_value_copyable.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.contract.function"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function function</span></h2>
<p>boost::contract::function — Program contracts for non-member, private and protected functions. </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../reference.html#header.boost.contract.function_hpp" title="Header &lt;boost/contract/function.hpp&gt;">boost/contract/function.hpp</a>&gt;

</span>
<a class="link" href="specify_precondit_idm35978.html" title="Class template specify_precondition_old_postcondition_except">specify_precondition_old_postcondition_except</a> <span class="identifier">function</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idm41086"></a><h2>Description</h2>
<p>This is used to specify preconditions, postconditions, exception guarantees, and old value copies at body for non-member, private and protected functions (these functions never check class invariants, see  <a class="link" href="../../boost_contract/contract_programming_overview.html#boost_contract.contract_programming_overview.function_calls" title="Function Calls"> Function Calls</a>):</p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="special">...</span><span class="special">)</span> <span class="special">{</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr</span><span class="special">&lt;</span><span class="identifier">old_type</span><span class="special">&gt;</span> <span class="identifier">old_var</span><span class="special">;</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">check</span> <span class="identifier">c</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">function</span><span class="special">(</span><span class="special">)</span>
        <span class="special">.</span><span class="identifier">precondition</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span> <span class="comment">// Optional.</span>
            <span class="identifier">BOOST_CONTRACT_ASSERT</span><span class="special">(</span><span class="special">...</span><span class="special">)</span><span class="special">;</span>
            <span class="special">...</span>
        <span class="special">}</span><span class="special">)</span>
        <span class="special">.</span><span class="identifier">old</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span> <span class="comment">// Optional.</span>
            <span class="identifier">old_var</span> <span class="special">=</span> <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr</span><span class="special">)</span><span class="special">;</span>  
            <span class="special">...</span>
        <span class="special">}</span><span class="special">)</span>
        <span class="special">.</span><span class="identifier">postcondition</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span> <span class="comment">// Optional.</span>
            <span class="identifier">BOOST_CONTRACT_ASSERT</span><span class="special">(</span><span class="special">...</span><span class="special">)</span><span class="special">;</span>
            <span class="special">...</span>
        <span class="special">}</span><span class="special">)</span>
        <span class="special">.</span><span class="identifier">except</span><span class="special">(</span><span class="special">[</span><span class="special">&amp;</span><span class="special">]</span> <span class="special">{</span> <span class="comment">// Optional.</span>
            <span class="identifier">BOOST_CONTRACT_ASSERT</span><span class="special">(</span><span class="special">...</span><span class="special">)</span><span class="special">;</span>
            <span class="special">...</span>
        <span class="special">}</span><span class="special">)</span>
    <span class="special">;</span>

    <span class="special">...</span> <span class="comment">// Function body.</span>
<span class="special">}</span>
</pre>
<p>This can be used also to program contracts in implementation code for lambda functions, loops, and arbitrary blocks of code. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.</p>
<p><span class="bold"><strong>See Also:</strong></span></p>
<p> <a class="link" href="../../boost_contract/tutorial.html#boost_contract.tutorial.non_member_functions" title="Non-Member Functions"> Non-Member Functions</a>,  <a class="link" href="../../boost_contract/advanced.html#boost_contract.advanced.private_and_protected_functions" title="Private and Protected Functions">
        Private and Protected Functions</a>,  <a class="link" href="../../boost_contract/advanced.html#boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__" title="Lambdas, Loops, Code Blocks (and constexpr)">
        Lambdas, Loops, Code Blocks</a></p>
<p>
</p>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p>The result of this function must be assigned to a variable of type  <code class="computeroutput"><a class="link" href="check.html" title="Class check">boost::contract::check</a></code> declared explicitly (i.e., without using C++11 <code class="computeroutput">auto</code> declarations) and locally just before the code of the function body (otherwise this library will generate a run-time error, see <code class="computeroutput"><a class="link" href="../../BOOST_CONTRACT_ON_idm34756.html" title="Macro BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</a></code>). </p></td>
</tr></tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p>
        Distributed under the Boost Software License, Version 1.0 (see accompanying
        file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="destructor.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.function_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="is_old_value_copyable.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
